package com.test.JVM;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

public class RefQueueDemo {

    public static void main(String[] args) {
        Object o = new Object();
        ReferenceQueue queue = new ReferenceQueue();
        WeakReference weakReference = new WeakReference(o,queue);

        System.out.println(o);
        System.out.println(weakReference.get());
        System.out.println(queue.poll());
        System.out.println("================");
        o = null;
        System.gc();

        System.out.println(o);
        System.out.println(weakReference.get());
        System.out.println(queue.poll());
    }
}
